package com.manli.wechat.utils.wxpay.config;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

import com.manli.wechat.utils.wxpay.sdk.IWXPayDomain;
import com.manli.wechat.utils.wxpay.sdk.WXPayConfig;
import com.manli.wechat.utils.wxpay.sdk.WXPayConstants;
import com.manli.wechat.utils.wxpay.sdk.IWXPayDomain.DomainInfo;


public class MyWxPayConfig extends WXPayConfig{
	private String certPath ;
	private String appID;
	private String mchID;
	private String key;
	private byte[] certData;
	
	public MyWxPayConfig(String certPath , String appID , String mchID , String key) throws Exception {
		this.certPath = certPath;
		this.appID = appID;
		this.mchID = mchID;
		this.key = key;
		
		File file = new File(certPath);
		InputStream certStream = new FileInputStream(file);
		this.certData = new byte[(int) file.length()];
		certStream.read(this.certData);
		certStream.close();
	}
	
	@Override
	public String getAppID() {
		// TODO Auto-generated method stub
		return this.appID;
	}

	@Override
	public String getMchID() {
		// TODO Auto-generated method stub
		return this.mchID;
	}

	@Override
	public String getKey() {
		// TODO Auto-generated method stub
		return this.key;
	}

	@Override
	public InputStream getCertStream() {
		ByteArrayInputStream certBis = new ByteArrayInputStream(this.certData);
        return certBis;
	}

	@Override
	public IWXPayDomain getWXPayDomain() {
		// TODO Auto-generated method stub
		return new IWXPayDomain() {
			
			@Override
			public void report(String domain, long elapsedTimeMillis, Exception ex) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public DomainInfo getDomain(WXPayConfig config) {
				// TODO Auto-generated method stub
				return new IWXPayDomain.DomainInfo(WXPayConstants.DOMAIN_API, true);
			}
		};
	}


	
}